#include <string>
using namespace std;
class Solution
{
public:
    bool backspaceCompare(string s, string t)
    {
        auto creat = [](string &s)
        {
            string ans;
            for (auto e : s)
            {
                if (!ans.empty() && e == '#')
                    ans.pop_back();
                else if (e != '#')
                    ans.push_back(e);
            }
            return ans;
        };
        string s1 = creat(s);
        string s2 = creat(t);
        if (s1 == s2)
            return true;
        else
            return false;
    }
};